package com.example.yiqiuser.service.impl;

import com.example.yiqiuser.dao.PtFavoriteDao;
import com.example.yiqiuser.entity.PtFavorite;
import com.example.yiqiuser.service.PtFavoriteService;
import com.example.yiqiuser.util.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @ fileName:PtFavoriteServiceImpl
 * @ description:
 * @ author:chen
 * @ createTime:2023/3/31 14:46
 * @ version:1.0.0
 */
@Service
public class PtFavoriteServiceImpl implements PtFavoriteService {


    @Resource
    private PtFavoriteDao favoriteDao;


    @Override
    public PageInfo queryByParam(Page<PtFavorite> page) {
        PageHelper.startPage(page.getPageNo(), page.getPageSize());
        PageInfo pageInfo = new PageInfo(favoriteDao.queryByParam(page.getData()));
        return pageInfo;
    }

    @Override
    public int add(PtFavorite ptFavorite) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = new Date();
        String format = simpleDateFormat.format(date);
        ptFavorite.setFavtime(format);
        return favoriteDao.add(ptFavorite);
    }

    @Override
    public int update(PtFavorite ptFavorite) {
        return favoriteDao.update(ptFavorite);
    }

    @Override
    public int deleteById(Integer id) {
        return favoriteDao.deleteById(id);
    }
    /**
     * 跟据objid删除
     * @param objid
     * @return
     */
    @Override
    public int deleteByObjid(String objid) {
        return favoriteDao.deleteByObjid(objid);
    }

}
